// fibonacci-worker.js (Worker 线程)
self.onmessage = function (e) {
    const n = e.data;
  
    // 计算斐波那契数列中的第 n 个数
    function fibonacci(n) {
      if (n <= 1) return n;
      let a = 0,
        b = 1,
        temp;
      for (let i = 2; i <= n; i++) {
        temp = a + b;
        a = b;
        b = temp;
      }
      return b;
    }
  
    // 将结果发送回主线程
    self.postMessage(fibonacci(n));
  };